Skip to content

Handle non-uniform C++ st_mtim.tv_sec vs Rust st_mtime#152

Merged
nunoplopes merged 7 commits into
Cpp2Rust:masterfrom
lucic71:st_mtime
May 27, 2026
Merged

Handle non-uniform C++ st_mtim.tv_sec vs Rust st_mtime#152
nunoplopes merged 7 commits into
Cpp2Rust:masterfrom
lucic71:st_mtime

Conversation

@lucic71
Copy link
Copy Markdown
Contributor

@lucic71 lucic71 commented May 26, 2026

struct stat contains a field called st_mtime. On Linux, this field is defined as a macro expansion to an internal field:

struct timespec st_mtim;    /* Time of last modification.  */

#  define st_mtime st_mtim.tv_sec

Rust libc does not contain the st_mtim field, it only contains st_mtime. To solve this tension, I rewrite all encoutners of ::struct stat::st_mtim::tv_sec as ::libc::stat::st_mtime.

I didn't want to touch the converter for this change, but I could not find a solution that only involved rules or the compat layer in cpp2rust/compat.

@lucic71 lucic71 changed the title Handle non-uniform C++ st_mtim.tv_sec with Rust st_mtime Handle non-uniform C++ st_mtim.tv_sec vs Rust st_mtime May 26, 2026
@nunoplopes
Copy link
Copy Markdown
Contributor

This is ok for now, but ofc it could have been done with rules.

Please add a test.

@lucic71
Copy link
Copy Markdown
Contributor Author

lucic71 commented May 27, 2026

This is ok for now, but ofc it could have been done with rules.

Please add a test.

I added a test

@lucic71 lucic71 marked this pull request as draft May 27, 2026 14:16
@lucic71 lucic71 marked this pull request as ready for review May 27, 2026 14:31
@nunoplopes nunoplopes merged commit cd2e414 into Cpp2Rust:master May 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants